package com.ruoyi.resource.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.resource.mapper.SysResourceMapper;
import com.ruoyi.resource.domain.SysResource;
import com.ruoyi.resource.service.ISysResourceService;

/**
 * 资源Service业务层处理
 * 
 * @author zzzyh
 * @date 2025-09-18
 */
@Service
public class SysResourceServiceImpl implements ISysResourceService 
{
    @Autowired
    private SysResourceMapper sysResourceMapper;


    /**
     * 查询资源
     * 
     * @param id 资源主键
     * @return 资源
     */
    @Override
    public SysResource selectSysResourceById(Long id)
    {
        return sysResourceMapper.selectSysResourceById(id);
    }

    /**
     * 查询资源列表
     * 
     * @param sysResource 资源
     * @return 资源
     */
    @Override
    public List<SysResource> selectSysResourceList(SysResource sysResource)
    {
        List<SysResource> sysResources = sysResourceMapper.selectSysResourceList(sysResource);
        for (SysResource resource : sysResources){
           String userName = sysResourceMapper.getUserNameByUserID(resource.getUserId());
            resource.setUserName(userName);
        }
        return sysResources;
    }

    /**
     * 新增资源
     * 
     * @param sysResource 资源
     * @return 结果
     */
    @Override
    public int insertSysResource(SysResource sysResource)
    {
        sysResource.setCreateTime(DateUtils.getNowDate());
        return sysResourceMapper.insertSysResource(sysResource);
    }

    /**
     * 修改资源
     * 
     * @param sysResource 资源
     * @return 结果
     */
    @Override
    public int updateSysResource(SysResource sysResource)
    {
        return sysResourceMapper.updateSysResource(sysResource);
    }

    /**
     * 批量删除资源
     * 
     * @param ids 需要删除的资源主键
     * @return 结果
     */
    @Override
    public int deleteSysResourceByIds(Long[] ids)
    {
        return sysResourceMapper.deleteSysResourceByIds(ids);
    }

    /**
     * 删除资源信息
     * 
     * @param id 资源主键
     * @return 结果
     */
    @Override
    public int deleteSysResourceById(Long id)
    {
        return sysResourceMapper.deleteSysResourceById(id);
    }

    @Override
    public Long getUserIdByUserName(String userName) {
        return sysResourceMapper.getUserIdByUserName(userName);
    }
}
